home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Gekikoh Dennoh Club 3
/
Gekikoh Dennoh Club Vol. 3 (Japan).7z
/
Gekikoh Dennoh Club Vol. 3 (Japan) (Track 1).bin
/
games
/
rifler
/
c
/
src.lzh
/
gl3togbg.c
next >
Wrap
Text File
|
1997-11-05
|
5KB
|
221 lines
/*
GL3ファイルを、GBGファイル(65536色BGPCG)に変換する。
VER 1.00
gl3togbg.x
a way to compile : "gcc -O gl3togbg.c"
BY SJOM
*/
#include <stdlib.h>
#include <stdio.h>
static char nooption_message[]=
" gl3togbg.x version 1.00
by SJOM \n
GL3ファイルを、GBGファイルに変換。
(GBGは65536色バックグラウンド用
PCGファイルです。)
実行:gl3togbg.x filename.gl3 quantity
filename.gl3 GL3ファイル名
quantity 変換PCG数 ";
#define no_error 0
#define extension_error 1
#define fileopen_error 2
#define nomemory_error 3
#define quantity_error 4
#define filedata_error 5
static char *error_message[]={
"No error !",
"This extension isn't \"gl3\" !",
"Cannot open this file !",
"Lack of memory !",
"Out of range of a commanded quantity !",
"There is something strange about this file !"
};
#define G_size 512*512 /* graphic memory word size */
#define null 0x00 /* null code */
#define g_line 28 /* number of pcg data in the line */
#define g_size 18 /* one pcg data length */
static int quantity;
static unsigned short *loaded_data;
/*
#include <sys/iocs.h>
void
escape(void)
{
if (_iocs_bitsns(0) & 2)
exit(0);
}
void
test(int data)
{
printf("TEST:%i\n",data);
while (!(_iocs_bitsns(6) & 32))
escape();
while ((_iocs_bitsns(6) & 32))
;
}
*/
static void
error_exit(int error_no)
{
puts(error_message[error_no]);
exit(error_no);
}
static void *
malloc_check(int size) /* allocate memory & check memory over error */
{
void *adress;
if ((adress=malloc(size))==NULL)
error_exit(nomemory_error);
return adress;
}
static int
tocapital(int ascii)
{
if ((ascii>='a') & (ascii<='z'))
ascii-=0x20;
return ascii;
}
static int
ext_check(const char *filename,const char *extension)
{
int loop,ext_len;
char *point=filename,*ext_sub=extension;
if (*extension==null)
return 0;
for (;;) { /* "."の位置サーチ */
if (*point==null)
return 1;
if (*point++=='.')
break;
/*point++;*/
};
for (ext_len=0;ext_len<4;ext_len++) { /* 拡張子の文字数 */
if (*ext_sub++==null)
break;
};
for (loop=0;loop<ext_len;loop++) { /* 拡張子のチェック */
if ((tocapital(*point)!=tocapital(*extension++)) || (*point==null))
return 1;
point++;
};
return 0;
}
static char *
copy_strings(char *base_str)
{
int loop,length;
char *copy_str;
for (length=0;base_str[length]!=null;length++)
;
copy_str=malloc_check(length+1);
for (loop=0;loop<length+1;loop++)
copy_str[loop]=*base_str++;
return copy_str;
}
static void
change_ext(char *filename,char *extension)
{
int loop;
for (loop=0;filename[loop]!='.';loop++)
;
loop++;
filename[loop++]=*extension++;
filename[loop++]=*extension++;
filename[loop]=*extension;
}
static int
fgetc_check(FILE *stream)
{
int data;
data=fgetc(stream);
if (data==EOF)
error_exit(filedata_error);
return data;
}
static void
fputword(int word,FILE *stream)
{
fputc(word/256,stream);
fputc(word & 255,stream);
}
static void
convert(char *gl3_filename)
{
int loop,counter,loop_x,loop_y,x_line,y_line,data;
FILE *gl3_stream,*gbg_stream;
char *gbg_filename;
gbg_filename=copy_strings(gl3_filename);
change_ext(gbg_filename,"GBG");
if ((gl3_stream=fopen(gl3_filename,"rb"))==NULL)
error_exit(fileopen_error);
loaded_data=malloc_check(G_size*2);
for (loop=0;loop<G_size;loop++) {
data=fgetc_check(gl3_stream);
data=data*256+fgetc_check(gl3_stream);
loaded_data[loop]=data;
};
fclose(gl3_stream);
if ((gbg_stream=fopen(gbg_filename,"wb"))==NULL)
error_exit(fileopen_error);
/*converted_data=malloc_check(quantity*16*16*2);*/
for (counter=0;counter<quantity;counter++) {
x_line=counter % g_line;
y_line=counter/g_line;
for (loop_y=0;loop_y<16;loop_y++)
for (loop_x=0;loop_x<16;loop_x++) {
/* converted_data[counter*16*16+loop_x+loop_y*16]= */
data=loaded_data[x_line*g_size+loop_x+(y_line*g_size+loop_y)*512];
fputword(data,gbg_stream);
};
};
fclose(gbg_stream);
}
int
main(int argc,char **argv)
{
if (argc!=3) {
puts(nooption_message);
exit(no_error);
};
if (ext_check(argv[1],"GL3"))
error_exit(extension_error);
quantity=atoi(argv[2]);
if ((quantity<1) || (quantity>28*28))
error_exit(quantity_error);
convert(argv[1]);
exit(no_error);
}